package spotGUI.mainFrameGUI;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;
import javax.swing.Timer;

import managers.EventsManager;
import spotGUI.optionsGUI.OptionsFrame;
import spotGUI.supportGUI.SupportFrame;
import spotGUI.utils.EmptyContentAreaButton;
import java.util.ResourceBundle;

public class StatusBar extends JPanel {
	
	private static final int STATUS_TIME = 10000;
	private JButton btnOptions;
	private JButton btnSupport;
	private JLabel status;
	
	private Timer t;
	private EmptyContentAreaButton btnEvents;

	/**
	 * Create the panel.
	 */
	public StatusBar() {
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{70, 70, 70, 51, 0};
		gridBagLayout.rowHeights = new int[]{53, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 60.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		btnOptions = new EmptyContentAreaButton(StatusBar.class.getResource("/images/Icons/48x48px/process.png"), "");
		btnOptions.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnOptions.setToolTipText(ResourceBundle.getBundle("spotGUI.mainFrameGUI.messages").getString("StatusBar.btnOptions.toolTipText")); //$NON-NLS-1$ //$NON-NLS-2$
		btnOptions.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				new OptionsFrame();
			}
		});
		GridBagConstraints gbc_btnOptions = new GridBagConstraints();
		gbc_btnOptions.insets = new Insets(0, 0, 0, 5);
		gbc_btnOptions.gridx = 0;
		gbc_btnOptions.gridy = 0;
		add(btnOptions, gbc_btnOptions);
		
		btnSupport = new EmptyContentAreaButton(StatusBar.class.getResource("/images/Icons/48x48px/info.png"), "");
		btnSupport.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnSupport.setToolTipText(ResourceBundle.getBundle("spotGUI.mainFrameGUI.messages").getString("StatusBar.btnSupport.toolTipText")); //$NON-NLS-1$ //$NON-NLS-2$
		btnSupport.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				new SupportFrame();
			}
		});
		GridBagConstraints gbc_btnSupport = new GridBagConstraints();
		gbc_btnSupport.insets = new Insets(0, 0, 0, 5);
		gbc_btnSupport.gridx = 1;
		gbc_btnSupport.gridy = 0;
		add(btnSupport, gbc_btnSupport);
		
		btnEvents = new EmptyContentAreaButton(StatusBar.class.getResource("/images/Icons/48x48/calendar.png"), null);
		btnEvents.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				EventsManager.getSharedInstance().setFrameVisible();
			}
		});
		btnEvents.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnEvents.setVerticalTextPosition(SwingConstants.BOTTOM);
		btnEvents.setToolTipText(ResourceBundle.getBundle("spotGUI.mainFrameGUI.messages").getString("StatusBar.btnEvents.toolTipText")); //$NON-NLS-1$ //$NON-NLS-2$
		btnEvents.setText("");
		btnEvents.setHorizontalTextPosition(SwingConstants.RIGHT);
		btnEvents.setFont(new Font("Agency FB", Font.BOLD, 25));
		GridBagConstraints gbc_btnEvents = new GridBagConstraints();
		gbc_btnEvents.insets = new Insets(0, 0, 0, 5);
		gbc_btnEvents.gridx = 2;
		gbc_btnEvents.gridy = 0;
		add(btnEvents, gbc_btnEvents);
		
		status = new JLabel("");
		status.setFont(new Font("Dialog", Font.BOLD, 12));
		GridBagConstraints gbc_status = new GridBagConstraints();
		gbc_status.anchor = GridBagConstraints.EAST;
		gbc_status.fill = GridBagConstraints.VERTICAL;
		gbc_status.gridx = 3;
		gbc_status.gridy = 0;
		add(status, gbc_status);
		
		t = new Timer(STATUS_TIME, new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				status.setText("");
				status.setToolTipText("");
			}
		});

	}


	
	public void setStatus(String text, Color color) {
		status.setText(text);
		status.setToolTipText(text);
		if (color != null)
			status.setForeground(color);
		t.restart();
	}
}
